/*
 * ModelObject.cpp
 *
 *  Created on: 03.10.2012
 *      Author: caffeine
 */

#include "ModelObject.h"

namespace irr{
namespace object{

ModelObject::ModelObject(ContainerNodeObject*c,irr::IrrlichtDevice*device):irr::ILoadableObject(device){
	container=c;
	if(container)
		container->grab();
	loaded=false;
}

ModelObject::~ModelObject() {
	unload();
	container->drop();
}

void ModelObject::on_load(){
	container->createContainer();
	on_model_load(container->getContainer());
	loaded=true;
}

void ModelObject::on_unload(){
	on_model_unload();
	container->destroyContainer();
	loaded=false;
}

bool ModelObject::setContainer(ContainerNodeObject*c){
	if (loaded)
		return false;
	if (container)
		container->drop();
	container=c;
	if (container)
		container->grab();
	return true;
}

ContainerNodeObject*ModelObject::getContainer(){
	return container;
}

}//namespace object
}//namespace irr
